package com.doordu.web.admin.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.doordu.admin.common.base.enums.PublicEnum;
import com.doordu.admin.common.base.enums.PublicStatusEnum;
import com.doordu.admin.service.user.api.RpPayProductService;
import com.doordu.admin.service.user.entity.RpPayProduct;

@RestController
public class PayProductRestController {
	@Autowired
	RpPayProductService rpPayProductService;

	@RequestMapping("/product/getById/{id}")
	public String getById(@PathVariable String id) {
		RpPayProduct entity = null;
		if (null == id) {
			return "product-id is not can bean null";
		}
		try {
			System.out.println("******dubbo consumer start");
			entity = rpPayProductService.getDataById(id);

			if (null != entity) {
				System.out.println("******" + entity.getProductCode());
			}
			System.out.println("******dubbo consumer end");
		} catch (Exception e) {
			System.out.println("******dubbo consumer exception");
			e.printStackTrace();
			return e.getMessage();
		}

		if (null != entity) {
			return JSONObject.toJSONString(entity);
		}
		return "product-" + id+ " is not exist";
	}

	@RequestMapping("/product/list")
	public String list() {
		List<RpPayProduct> result = null;
		try {
			result = rpPayProductService.listAll();
		} catch (Exception e) {
			return e.getMessage();
		}

		return JSONObject.toJSONString(result);
	}
}
